package com.ywk.base.designPattern.proxy.dynamicProxy.jdk;

import com.ywk.base.designPattern.proxy.dynamicProxy.jdk.animal.Animal;
import com.ywk.base.designPattern.proxy.dynamicProxy.jdk.animal.Dog;
import com.ywk.base.designPattern.proxy.dynamicProxy.jdk.person.Doctor;
import com.ywk.base.designPattern.proxy.dynamicProxy.jdk.person.Person;

import java.lang.reflect.Proxy;

/**
 * @Author zbh
 * @Date 2023/4/3
 */
public class JDKProxyTest {


    public static void main(String[] args) {
        JDKProxy proxy;

        proxy = new JDKProxy(new Dog("旺旺"));
        Animal dog = (Animal) Proxy.newProxyInstance(proxy.getClass().getClassLoader(), new Class[]{Animal.class}, proxy);
        dog.wakeup();
        dog.sleep();

        System.out.println("=====================");

        proxy = new JDKProxy(new Doctor("王教授"));
        Person doctor = (Person) Proxy.newProxyInstance(proxy.getClass().getClassLoader(), new Class[]{Person.class}, proxy);
        doctor.wakeup();
        doctor.sleep();


    }
}
